package com.suxin.webflux.workshop.service;

import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.*;

/**
 * @Classname QuoteRouteFunction
 * @Description [ TODO ]
 * @Author Tang
 * @Date 2021/1/4 16:01
 * @Created by ASUS
 */
@Component
public class QuoteRouteFunction {

    @Bean
    public RouterFunction<ServerResponse> route(QuoteHandler quoteHandler) {
        return RouterFunctions
                .route(RequestPredicates.GET("/hello").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
                        quoteHandler::hello)
                .andRoute(RequestPredicates.POST("/echo").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
                        quoteHandler::echo)
                .andRoute(RequestPredicates.GET("/quotes").and(RequestPredicates.accept(MediaType.APPLICATION_JSON)),
                        quoteHandler::fetchQuotes)
                .andRoute(RequestPredicates.GET("/quotes").and(RequestPredicates.accept(MediaType.APPLICATION_STREAM_JSON)),
                        quoteHandler::streamQuotes);
    }

}